package com.onedec.designer.service.impl;

import com.onedec.designer.entity.OnedecContract;
import com.onedec.designer.entity.OnedecContractExample;
import com.onedec.designer.entity.OnedecFloorPlan;
import com.onedec.designer.entity.OnedecFloorPlanExample;
import com.onedec.designer.mapper.OnedecContractMapper;
import com.onedec.designer.mapper.OnedecFloorPlanMapper;
import com.onedec.designer.service.OnedecContractService;
import com.onedec.designer.service.OnedecFloorPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class OnedecContractServiceImpl implements OnedecContractService {
    @Autowired
    private OnedecContractMapper onedecContractMapper;


    @Override
    public List<Map<String, Object>> selectByMap(Map<String, Object> map) {
        return onedecContractMapper.selectByMap(map);
    }

    @Override
    public long accountnum() {
        return onedecContractMapper.countByExample(null);
    }

    @Override
    public void deleteById(int id) {
        onedecContractMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insertOne(OnedecContract onedecContract) {
        onedecContractMapper.insertSelective(onedecContract);
    }


    @Override
    public OnedecContract selectById(int id) {
        return onedecContractMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(OnedecContract onedecContract) {
        onedecContractMapper.updateByPrimaryKeySelective(onedecContract);
    }

    @Override
    public void updateById(int id) {
        OnedecContract onedecContract = onedecContractMapper.selectByPrimaryKey(id);
        onedecContract.setContractStatus("1");
        onedecContractMapper.updateByPrimaryKeySelective(onedecContract);
    }

    @Override
    public void rejectById(int id) {
        OnedecContract onedecContract = onedecContractMapper.selectByPrimaryKey(id);
        onedecContract.setContractStatus("3");
        onedecContractMapper.updateByPrimaryKeySelective(onedecContract);
    }

    @Override
    public List<OnedecContract> selectByProjectId(int id) {
        OnedecContractExample onedecContractExample = new OnedecContractExample();
        OnedecContractExample.Criteria or = onedecContractExample.or();
        or.andContractProjectIdEqualTo(id);

        return onedecContractMapper.selectByExample(onedecContractExample);
    }
}
